#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 2e5 + 10;

char s[N];
int pre[3][N], n, K, y, z, t;

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, K = in; scanf("%s", s + 1); rep(i, 1, n) s[i] = s[i] == 'J' ? 0 : s[i] == 'O' ? 1 : 2;
	rep(i, 1, n) rep(j, 0, 2) pre[j][i] = pre[j][i - 1] + (s[i] == j);
	int ans = n + 10;
	rep(x, 0, n) {
		while(y <= n && pre[0][y] - pre[0][x] < K) y++;
		while(z <= n && pre[1][z] - pre[1][y] < K) z++;
		while(t <= n && pre[2][t] - pre[2][z] < K) t++;
		if(y > n || z > n || t > n) break; chkmin(ans, t - x - 3 * K);
	} if(ans > n) ans = -1; printf("%d\n", ans); return 0;
}
